<?php
namespace V1;
class UserFeedback extends \ResourceClass
{
    public $isActive = true;
    public $remark = '意见反馈';


    /*
     * 参数说明
     * uid 反馈人id
     * content 反馈内容
     * userType(1企业客户，2企业用户)
     * */
    public function post (array $req, array $post, &$result) {
        if (!isset($req['uid'])) {
            return 'require user uid';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }
        $user_cls = \Biz\UserHandler::getById($req['userType'], $req['uid']);
        if (!is_object($user_cls)) {
            return 'data illegal';
        }
        if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'], $user_cls->getEnterpriseId(), $req['t'] . $post['payload'], $req['k']) !== true) {
            return 'data illegal';
        }

        $data = base64_decode($post['payload']);
        @parse_str($data,$data);
        if(!array_key_exists('content',$data)){
            return 'require content info';
        }

        $user_id = (int)$req['uid'];
        $user_type = (int)$req['userType'];
        $enterprise_id = 0;// 目前没有
        $content = (string)$data['content'];

        $feedback_cls = new \Cls\Message\Feedback();
        $feedback_cls->create($user_id, $user_type, $enterprise_id, $content);

        if (\Biz\MessageHandler::addFeedback($feedback_cls) !== true) {
            return 'failed';
        }

        // $insertdata = array(
        //     'uid' => $req['uid'],
        //     'content' => $data['content'],
        //     'user_type' => $req['userType']
        // );
        // UserFeedbackModel::insertFeedback($insertdata);
        return '';
    }
}